'use strict'
const through = require('through2')
module.exports = function () {
	return through.obj(function (file, enc, cb) {
		if (file.isNull()) {
			cb(null, file);
			return;
		}
		if (file.isStream()) {
			console.log('Streaming not supported');
			return;
		}
        
		const fileReg = /\s(?=\s)/gi;
		let data = file.contents.toString();
		let dataReplace = data.replace(fileReg, "") + '';
		dataReplace = dataReplace.replace(/;\n}/gi, "; }") + '';
		//针对多个`,`的属性
		dataReplace = dataReplace.replace(/,\n/gi, ", ") + '';
		//针对media的情况
		dataReplace = dataReplace.replace(/}\n}/gi, "} }") + '';
		file.contents = new Buffer(dataReplace)
		cb(null, file)
	})
}